home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / test / locale / old / helloworld.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  2.6 KB  |  122 lines

  1. ;/* Sample use of CatComp
  2.  
  3. CatComp helloworld.cd cfile helloworld_strings.h objfile helloworld_strings.o
  4. Quit
  5. */
  6.  
  7. #include <exec/types.h>
  8. #include <libraries/locale.h>
  9. #include <stdio.h>
  10.  
  11. #include <clib/exec_protos.h>
  12. #include <clib/locale_protos.h>
  13.  
  14. /*
  15. #include <pragmas/exec_pragmas.h>
  16. #include <pragmas/locale_pragmas.h>
  17. */
  18.  
  19. #define CATCOMP_NUMBERS
  20. #define CATCOMP_BLOCK
  21. #define CATCOMP_STRINGS     // for demonstrating the reverse index functions
  22. #include "helloworld_strings.h"
  23.  
  24.  
  25. extern struct Library *SysBase;
  26. struct Library *LocaleBase;
  27.  
  28.  
  29. #define Prototype extern
  30.  
  31. Prototype STRPTR GetString(LONG stringNum);
  32. Prototype LONG GetIndex(STRPTR string);
  33. Prototype void openCatalog(char *name);
  34. Prototype void closeCatalog(void);
  35.  
  36. APTR Catalog = NULL;
  37.  
  38. VOID main(VOID)
  39. {
  40.     LocaleBase = OpenLibrary("locale.library",38);
  41.     openCatalog("helloworld.catalog");
  42.  
  43.     printf("%s\n",GetString(MSG_HELLO));
  44.     printf("%s\n",GetString(MSG_BYE));
  45.  
  46.     printf("Cat Index of [%s] is %d\n",MSG_BYE_STR,GetIndex(MSG_BYE_STR));
  47.     printf("Cat Index of [%s] is %d\n",MSG_HELLO_STR,GetIndex(MSG_HELLO_STR));
  48.  
  49.     printf("%s\n",GetString(GetIndex(MSG_HELLO_STR)));
  50.  
  51.     closeCatalog();
  52.     if (LocaleBase)CloseLibrary(LocaleBase);
  53. }
  54.  
  55.  
  56. STRPTR GetString(LONG stringNum)
  57. {
  58. LONG   *l;
  59. UWORD  *w;
  60. STRPTR    builtIn;
  61.  
  62.     l = (LONG *)CatCompBlock;
  63.  
  64.     while (*l != stringNum)
  65.     {
  66.     w = (UWORD *)((ULONG)l + 4);
  67.     l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  68.     }
  69.     builtIn = (STRPTR)((ULONG)l + 6);
  70.  
  71.     printf("Catalog %08lx\n", Catalog);
  72.  
  73.     printf("GetString: %d %08lx\n", stringNum, GetCatalogStr(Catalog, stringNum, NULL));
  74.     printf("GetString: %d %s\n", 1, GetCatalogStr(Catalog, 1, NULL));
  75.     printf("GetString: %d %08lx\n", 0, GetCatalogStr(Catalog, 0, NULL));
  76.     printf("GetString: %d %08lx\n", 2, GetCatalogStr(Catalog, 2, NULL));
  77.  
  78.     if (LocaleBase)
  79.     return(GetCatalogStr(Catalog,stringNum,builtIn));
  80.  
  81.     return(builtIn);
  82. }
  83.  
  84.  
  85. /* Given a string, scan through the local strings and find the index number
  86.  * which is used to access locale.library to get the string in the
  87.  * current catalog
  88.  */
  89.  
  90. LONG GetIndex(STRPTR string)
  91. {
  92. LONG   *l;
  93. UWORD  *w;
  94. STRPTR    builtIn;
  95.  
  96.     l = (LONG *)CatCompBlock;
  97.     builtIn = (STRPTR)((ULONG)l + 6);
  98.  
  99.     while (Stricmp(builtIn,string)) {
  100.     w = (UWORD *)((ULONG)l + 4);
  101.     l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  102.     builtIn = (STRPTR)((ULONG)l + 6);
  103.     }
  104.  
  105.     return *l;
  106. }
  107.  
  108. void openCatalog(char *name)
  109. {
  110. static struct TagItem tags[3] = {
  111.     OC_Language,"english",
  112.     OC_BuiltInLanguage,"none",
  113.     TAG_DONE, NULL};
  114.  
  115.    if(LocaleBase)Catalog  = OpenCatalogA(NULL,name,tags);
  116. }
  117.  
  118. void closeCatalog(void)
  119. {
  120.    if(LocaleBase && Catalog)CloseCatalog(Catalog);
  121. }
  122.